package com.j180.controller;

import com.j180.bean.BookBean;
import com.j180.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {
      @Autowired
      private IBookService iBookService;
      @GetMapping("/showAll")
    public List<BookBean> showAllBooks(){

        return iBookService.showAllBooks();
    }

    @PostMapping("/add")
    public String addBook(BookBean bookBean){

       int num =  iBookService.addBook(bookBean);

       if(num>0){
           return "ok";
       }else{
           return "no";
       }
    }

    @GetMapping("/showdetail/{bookid}")
    public BookBean getBookInfo(@PathVariable("bookid") int id){

          return iBookService.showBookById(id);
    }

    @PutMapping("/update")
    public String updateInfo(BookBean bookBean){
         int num = iBookService.updatetBookInfo(bookBean);

        if(num>0){
            return "ok";
        }else{
            return "no";
        }

    }

    @DeleteMapping("/delete/{id}")
    public  String  delete(@PathVariable("id") int id){
        int num = iBookService.deleteBookInfo(id);
        if(num>0){
            return "ok";
        }else{
            return "no";
        }

    }



}
